﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace W8Shortcuts
{
    public partial class W8CS_window : Form
    {
        public W8CS_window()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SendKeys.Send("^{ESC}"); // CTRL + ESC opens Start menu screen. Note ALT-HOME %{HOME} did not work here.
        }

        private void b_charms_Click(object sender, EventArgs e)
        {
            // call the custom KeyboardSend class with key combos
            KeyboardSend.KeyDown(Keys.LWin); 
            KeyboardSend.KeyDown(Keys.C);
            KeyboardSend.KeyUp(Keys.LWin);
            KeyboardSend.KeyUp(Keys.C);
        }
    }



    static class KeyboardSend 
        // thanks to Nolwenn Le Guen at http://stackoverflow.com/questions/6407584/sendkeys-send-and-windows-key
{
    [DllImport("user32.dll")]
    private static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

    private const int KEYEVENTF_EXTENDEDKEY = 1;
    private const int KEYEVENTF_KEYUP = 2;

    public static void KeyDown(Keys vKey)
    {
        keybd_event((byte)vKey, 0, KEYEVENTF_EXTENDEDKEY, 0);
    }

    public static void KeyUp(Keys vKey)
    {
        keybd_event((byte)vKey, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
    }

}
}
